<?php require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('admanage','list'); 
$starttimer = microtime(true);
$checkPagenum = isset($checkPagenum) ? $checkPagenum : $cfg_pagenum;
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>广告管理</title>
<link href="templates/css/style.css" rel="stylesheet" type="text/css" />
<link href="templates/css/pagination.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="templates/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/layindex.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/common.js"></script>
<script type="text/javascript" src="templates/js/loadimage.js"></script>
<script type="text/javascript" src="templates/js/forms.func.js"></script>
<script type="text/javascript">
$(function(){
    $(".thumbs img").LoadImage();
});

function checkPagenum(id)
{	
	var pn = document.getElementById(id).value; 
	var url=window.location.search;
	location.href=changeURLArg(url,'checkPagenum',pn);
};

function func(id){
 //获取被选中的option标签
	var val = $('#'+id+' option:selected').val();
	var url=window.location.search;
	location.href=changeURLArg(url,id,val);
};
</script>
</head>

<body class="mainbody">
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
  <a href="home.php" class="home"><i></i><span>首页</span></a>
  <i class="arrow"></i>
  <span>广告管理</span>
  <a href="javascript:location.reload();" class="reload">刷新</a>
</div>
<!--/导航栏-->
<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"></a>
      <div class="l-list">
        <ul class="icon-list">
		 <?php if(IsModel('admanage','add',1)!=false) echo'<li><a href="admanage_add.php" class="add"><i></i><span>添加新广告</span></a></li>';?>
		  <li><a class="all" href="javascript:;" onclick="checkAll(this);"><i></i><span>全选</span></a></li>
		  <?php if(IsModel('admanage','del',1)!=false) echo'<li><a href="javascript:DelAllList(\'admanage_save.php\');" onclick="return ConfDelAll(0);" class="del"><i></i><span>删除</span></a></li>';?>
        </ul> 
		<div class="rule-single-select">
		<select name="tid" onchange="func('tid')" id="tid">
			<option selected="selected" value="all">查看全部</option>
			<?php
			$dosql->Execute("SELECT * FROM `#@__adtype` ORDER BY orderid ASC");
			while($row = $dosql->GetArray())
			{	if(@$tid==$row['id']) $select='selected="selected"';else $select=''; 
				echo '<option '.$select.' value="'.$row['id'].'">'.$row['classname'].'</option>';
			}
			?>
		</select>
         </div>
		  <?php if(IsModel('adtype','list',1)!=false) echo'<span><a href="adtype.php">广告位管理</a></span>';?>
	
      </div>
    
    </div>
  </div>
</div>

<form name="form" id="form" method="post" action="admanage_save.php">
<div class="table-container">
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="ltable">
		<tr align="center">
			<th width="5%"><input type="checkbox" name="checkid" id="checkid" onclick="CheckAll(this.checked);"></td>
			<th width="5%">ID</th>
			<th width="10%">缩略图</th>
			<th width="25%">广告标识</th>
			<th width="20%">投放范围</th>
			<th width="15%">广告形式</th>
			<th width="20%">操作</th>
		</tr>
		<?php

		//设置SQL
		$sql = "SELECT * FROM `#@__admanage` WHERE `siteid`='$cfg_siteid'";
	
		if(isset($tid))
				if($tid=='all')
			{
				$sql .='';
			}
			else{$sql .= "AND `classid`=$tid";}

		$dopage->GetPage($sql);
		while($row = $dosql->GetArray())
		{

			//分类名称
			$r = $dosql->GetOne("SELECT `classname` FROM `#@__adtype` WHERE `id`=".$row['classid']);

			if(isset($r['classname']))
				$classname = $r['classname'].' ['.$row['classid'].']';
			else
				$classname = '<span class="red">分类已删除 ['.$row['classid'].']</span>';
			
			//删除权限
			if(IsModel('admanage','del',1)!=false)
				$delStr = '<a href="admanage_save.php?action=del2&id='.$row['id'].'" onclick="return ConfDel(0);">删除</a>';
			else
				$delStr = '删除';
			
			//修改权限
			if(IsModel('admanage','update',1)!=false)
				$updateStr = '<a href="admanage_update.php?id='.$row['id'].'"">修改</a>';
			else
				$updateStr = '修改';
				
					//审核状态
			switch($row['checkinfo'])
			{
				case 'true':
					$checkinfo = '显示';
					break;  
				case 'false':
					$checkinfo = '隐藏';
					break;
				default:
					$checkinfo = '没有获取到参数';
			}
			
			//审核权限
			if(IsModel('admanage','Audit',1)!=false)
				$checkStr = '<a href="admanage_save.php?action=check&id='.$row['id'].'&checkinfo='.$row['checkinfo'].'" title="点击进行审核与未审操作">'.$checkinfo.'</a>';
			else
				$checkStr = $checkinfo;
				
		
		?>
		<tr align="center" >
			<td height="70"><input type="checkbox" name="checkid[]" id="checkid[]" value="<?php echo $row['id']; ?>" /></td>
			<td><?php echo $row['id']; ?></td>
			<td><span class="thumbs"><?php echo GetMgrThumbs($row['picurl']); ?></span></td>
			<td><?php echo $row['title']; ?></td>
			<td><?php echo $classname; ?></td>
			<td><?php echo $row['admode']; ?></td>
			<td class="action endCol"><span><?php echo $checkStr;?></span> | <span><?php echo $updateStr;?></span> | <span class="nb"><?php echo $delStr;?></span></td>
		</tr>
		<?php
		}
		?>
		<?php

//判断无记录样式
if($dosql->GetTotalRow() == 0)
{
		echo '<tr><td align="center" colspan="7">暂无记录</td></tr>';
}
?>
	</table>

</div>
</form>
<!--内容底部-->
<div class="line20"></div>
<div class="pagelist">
  <div class="l-btns">
    <span>显示</span><input name="txtPageNum" type="text" value="<?php echo $checkPagenum;?>"  onblur="checkPagenum(this.id)"  onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="txtPageNum" class="pagenum" onkeydown="return checkNumber(event);" /><span>条/页</span>
  </div>
   <?php echo $dopage->GetList($sql,$checkPagenum); ?>
  <div class="l-btns"><span>
<?php 
$stoptimer = microtime(true);
$timer = $stoptimer-$starttimer;
echo " $timer s";?></span>
</div>
</div>
<!--/内容底部-->
</body>
</html>